package com.gxa.logistics.service.impl;

import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.EmployeeSaveDTO;
import com.gxa.logistics.domain.dto.EmployeeUpdateDTO;
import com.gxa.logistics.domain.dto.MenuSaveDTO;
import com.gxa.logistics.domain.dto.MenuUpdateDTO;
import com.gxa.logistics.domain.entity.Menu;
import com.gxa.logistics.mapper.MenuMapper;
import com.gxa.logistics.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;

    @Override
    public RespResult<List<Menu>> list() {
        List<Menu> menuList = menuMapper.findMenu();

        //使用流操作将menuList转化为parentMenuList
        List<Menu> parentMenuList = menuList.stream()
                .filter(menu -> menu.getParentId() == 0)
                .collect(Collectors.toList());

        for(Menu parentMenu:parentMenuList){
            parentMenu.setChildMenu(menuList.stream()
                    .filter(menu -> menu.getParentId().equals(parentMenu.getMenuId())).collect(Collectors.toList()));
        }

        return RespResult.success(parentMenuList);
    }

    @Override
    public void insertMenu(MenuSaveDTO menuSaveDTO) {
        menuMapper.insertMenu(menuSaveDTO);
    }

    @Override
    public void updateMenu(MenuUpdateDTO menuUpdateDTO) {
        menuMapper.updateMenu(menuUpdateDTO);
    }

    @Override
    public void deleteMenuById(Integer menuId) {
        menuMapper.deleteMenuById(menuId);
    }



   /* }



    @Override
    public void updateMenu(MenuUpdateDTO menuUpdateDTO) {
        menuMapper.updateMenu(menuUpdateDTO);
    }

    @Override


    @Override
    public void freezeMenuById(Integer menuId) {
        menuMapper.freezeMenuById(menuId);
    }*/
}
